package com.meixiang.activity.account.managers;

import android.content.Intent;
import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;

import com.meixiang.R;
import com.meixiang.adapter.bank.ChooseBankCardAdapter;
import com.meixiang.entity.BankBean;
import com.meixiang.global.Config;
import com.meixiang.http.HttpCallBack;
import com.meixiang.http.HttpUtils;
import com.meixiang.main.BaseActivity;
import com.meixiang.recyclerview.OnItemClick;
import com.meixiang.util.AbToastUtil;

import org.json.JSONObject;

import java.util.ArrayList;
import java.util.List;

import butterknife.Bind;
import butterknife.ButterKnife;

/**
 * 银行卡 选择银行
 *
 * @author zys
 */
public class ChooseBankCardActivity extends BaseActivity {
    @Bind(R.id.choose_bank_recycler)
    RecyclerView chooseBankRecycler;

    private List<BankBean> bankList = new ArrayList<BankBean>();
    private ChooseBankCardAdapter mAdapter;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        setContentView(R.layout.activity_select_bank_card);
        ButterKnife.bind(this);
        super.onCreate(savedInstanceState);

    }

    @Override
    protected void initTitle() {
        setTitle("选择银行");
//        title.showRightButton(new View.OnClickListener() {
//            @Override
//            public void onClick(View v) {
//                // TODO Auto-generated method stub
//
//            }
//        });
//        title.setLeftImageButton(R.mipmap.back);
//        title.showLeftButton(new View.OnClickListener() {
//            @Override
//            public void onClick(View v) {
//                finish();
//            }
//        });
    }

    @Override
    protected void initView() {
        LinearLayoutManager linearLayoutManager = new LinearLayoutManager(this);
        linearLayoutManager.setOrientation(LinearLayoutManager.VERTICAL);
        chooseBankRecycler.setLayoutManager(linearLayoutManager);
        mAdapter = new ChooseBankCardAdapter();
        //String imageUrl, String bankName, String bankId
        bankList.add(new BankBean("", "农业银行", "420832347093724"));//农业
//        bankList.add(new BankBean("", "中国银行", "420832347093724"));//中国银行
//        bankList.add(new BankBean("", "交通银行", "420832347093724"));//交通银行
//        bankList.add(new BankBean("", "建设银行", "420832347093724"));//建设银行
        mAdapter.setData(bankList);
        chooseBankRecycler.setAdapter(mAdapter);
        mAdapter.setOnItemClickListener(new OnItemClick() {
            @Override
            public void onItemClick(View view, int position) {
                Intent intent = new Intent(ChooseBankCardActivity.this,
                        BindBankCardActivity.class);
                intent.putExtra("bankName",bankList.get(position).getBankName());
                intent.putExtra("bankId",bankList.get(position).getBankId());
                setResult(200, intent);
               finish();
            }
        });

    }

    @Override
    protected void setData() {
        getBankListSelect();
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        ButterKnife.unbind(this);
    }


    @Override
    public void onClick(View v) {

    }
    /*
    *
    * 选择银行卡
    * **/
    private void getBankListSelect(){
        HttpUtils.post(Config.MY_ACCOUNT_BANKBILISTSELETCT,null, new HttpCallBack(ChooseBankCardActivity.this) {
            @Override
            public void onSucceed(JSONObject result, String code, String message) {
                if (code.equals("0")){
                   // BankBean  bk = AbJsonUtil.fromJson(result.toString(),BankBean.class);
                   // mAdapter.setData(bankList);
                    AbToastUtil.showToast(ChooseBankCardActivity.this,message);
                }else {
                    AbToastUtil.showToast(ChooseBankCardActivity.this,message);
                }
            }

            @Override
            public void onError(String code, String message) {
                AbToastUtil.showToast(ChooseBankCardActivity.this,message);
            }
        });



    }

}
